<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%java.util.Random r=new java.util.Random();  %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function back(){
		window.location.href = "./customerManage.do";
		window.location.target = "main";
	}
	
	function advancedQueryDialog(){
		var url = "./customerManage.do?action=deptAdvancedQueryCustomer&radom="+<%=r.nextInt(100)%>;
		var dlgParam = "dialogHeight:360px;dialogWidth:450px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		var rt = window.showModalDialog(url,"",dlgParam);
		if(rt != undefined){		
			//根据从子窗口得到的值，从中提取customerCode,customerName,industryId,areaId,salePersonId,
			//customerSourceId,requireDesc,startCreateDate,endCreateDate,startLastLinkDate,endLastLinkDate
			var tStr = rt.split(",");
			document.getElementById("customerCode").value = tStr[0];										
			document.getElementById("customerName").value = tStr[1];
			document.getElementById("industryId").value = tStr[2];
			document.getElementById("areaId").value = tStr[3];
			document.getElementById("salePersonId").value = tStr[4];
			document.getElementById("customerSourceId").value = tStr[5];
			document.getElementById("requireDesc").value = tStr[6];
			document.getElementById("startCreateDate").value = tStr[7];
			document.getElementById("endCreateDate").value = tStr[8];
			document.getElementById("startLastLinkDate").value = tStr[9];
			document.getElementById("endLastLinkDate").value = tStr[10];
			
			document.getElementById("sFlag").value = "2";
			document.deptCustomerForm.action = "./customerManage.do?action=deptCustomer";
			document.deptCustomerForm.target = "main";
			document.deptCustomerForm.submit();
		}
	}
	
	function recordSort(record,imgId){
		var viewType = "<c:out value='${viewType}'/>";
		var sortRecord = "<c:out value='${queryCustomer.sortRecord}'/>";
		var sortWay = "<c:out value='${queryCustomer.sortWay}'/>";
		if(sortRecord == record){
			if(sortWay == "asc"){
				document.getElementById("sortWay").value = "desc";
				document.getElementById(imgId).src = "./images/arrow_down.gif";
			}else if(sortWay == "desc"){
				document.getElementById("sortWay").value = "asc";
				document.getElementById(imgId).src = "./images/arrow_up.gif";
			}else{
				document.getElementById("sortWay").value = "desc";
				document.getElementById(imgId).src = "./images/arrow_down.gif";
			}
		}else{
			document.getElementById("sortWay").value = "asc";
			document.getElementById(imgId).src = "./images/arrow_up.gif";
		}
		document.getElementById("sortRecord").value = record;
		document.getElementById("sortSign").value = "1";
		
		//alert(document.getElementById("sortRecord").value + "==="+ document.getElementById("sortWay").value);
		document.deptCustomerForm.action = "./customerManage.do?action=deptCustomer&imgId="+imgId;
		document.deptCustomerForm.target = "main";
		document.deptCustomerForm.submit();
	}
	
	function pageCustomer(flag){
		document.deptCustomerForm.action = "./customerManage.do?action=deptCustomer&flag="+flag;
		document.deptCustomerForm.target = "main";
		document.deptCustomerForm.submit();
	}
	
	function initPage(){
		if("<c:out value='${deleteResult}'/>" == '1'){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
		d.style.width = (document.body.scrollWidth - 32) +"px";
		tp.style.width = (document.body.scrollWidth - 32) +"px";
		
		//字段排序用
		var sortWay = "<c:out value='${queryCustomer.sortWay}'/>";
		var imgId = "<c:out value='${imgId}'/>";
		if(sortWay == "asc"){
			document.getElementById(imgId).src = "./images/arrow_up.gif";
		}else if(sortWay == "desc"){
			document.getElementById(imgId).src = "./images/arrow_down.gif";
		}else{
			document.getElementById(imgId).src = "./images/arrow_off.gif";
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="deptCustomerForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab">部门客户资料</td>
					</tr>
					<tr>
						<td valign="bottom" class="a_tools" style="padding-left: 3px;padding-top: 4px;">
							<a class="asearch" href="javascript:advancedQueryDialog();" hidefocus="true">高级查询</a>
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td class="title_lab">部门客户资料</td>
						<td align="right" valign="">
							<!-- page -->
							<table class="table_page2">
								<tr>
									<td valign="bottom">
										<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
										<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
										<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
										共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>&nbsp;&nbsp;&nbsp;
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr><td colspan="3" height="2"></td></tr>
					<tr>
						<td colspan="2" valign="top">
							<table class="table">
								<tr>
									<td valign="top">
										<div id="d" style="width:850px;height:100%;overflow-x: scroll;overflow-y: hidden;">
										<table class="table_style" style="width: 1900px;  word-break:break-all">
											<tr>
												<td class="title" width="8"></td>
												<td class="title" width="30">共享</td>
												<td class="title" width="30">状态</td>
												<td class="title" width="300">客户名称</td>
												<td class="title" width="50">销售代表</td>
												<td class="title" width="60">建档日期</td>		
												<td class="title_sort" width="60" onclick="recordSort('lastLink','16')">
													最后联系<img id="16" src="./images/arrow_off.gif" style="vertical-align: middle;">
												</td>
												<td class="title" width="120">注册地址</td>													
												<td class="title" width="250">销售进度</td>									
												<td class="title" width="100">联系电话</td>
												<td class="title" width="60">来源</td>

												<td class="title_sort" width="60" onclick="recordSort('industryId','9')">
													行业<img id="9" src="./images/arrow_off.gif" style="vertical-align: middle;">
												</td>
												<td class="title_sort" width="60" onclick="recordSort('areaId','10')">
													区域<img id="10" src="./images/arrow_off.gif" style="vertical-align: middle;">
												</td>
												<td class="title" width="60">联系人</td>
												<td class="title" width="60">联系次数</td>
												<td class="title_sort" width="60" onclick="recordSort('saleStageId','13')">
													销售阶段<img id="13" src="./images/arrow_off.gif" style="vertical-align: middle;">
												</td>
												<td class="title_sort" width="90" onclick="recordSort('predictCost','14')">
													预测签约<img id="14" src="./images/arrow_off.gif" style="vertical-align: middle;">
												</td>
												<td class="title_sort" width="90" onclick="recordSort('predictContract','15')">
													预测签约时间<img id="15" src="./images/arrow_off.gif" style="vertical-align: middle;">
												</td>

											</tr>
											<c:choose>
											<c:when test="${not empty customers}">
											<c:forEach var="customer" items="${customers}">
											<tr onmouseover="onmousemoveChange(this,'img${customer.id}')" onmouseout="onmouseoutChange(this,'img${customer.id}')">
												<td height="16" width="8" align="right"><img id="img${customer.id}" src="./images/table_sign2.bmp"></td>
												<td align="center">
													<c:if test="${customer.isShare == 1}">
													<img class="btn_img" src="./images/share.gif" onclick="" title="<fmt:message key='customer.lable.share'/>">
													</c:if>
												</td>
												<td align="center">
													<c:if test="${customer.isFollow == 1}">
													<img class="btn_img" src="./images/follow.gif" onclick="" title="<fmt:message key='customer.lable.follow'/>">&nbsp;&nbsp;
													</c:if>
												</td>
												<td align="left"><a href="./customerManage.do?action=customerDetail&customerId=${customer.id}&sign=12" target="main">${customer.customerName}</a></td>
												<td>${customer.salePerson}</td>
												<td><fmt:formatDate value="${customer.createDate}" pattern="yyyy-MM-dd"/></td>
												<td><fmt:formatDate value="${customer.lastLink}" pattern="yyyy-MM-dd"/></td>
												<td>${customer.summaryAddress}</td>
												<td>${customer.customItem2}</td>												
												<td>${customer.phone}</td>
												<td>
													<c:choose>
														<c:when test="${customer.customerSourceId == 1}"><fmt:message key='customer.select.self'/></c:when>
														<c:when test="${customer.customerSourceId == 2}"><fmt:message key='customer.select.companySet'/></c:when>
														<c:when test="${customer.customerSourceId == 3}"><fmt:message key='customer.select.market'/></c:when>
														<c:otherwise><fmt:message key='customer.select.other'/></c:otherwise>
													</c:choose>
												</td>
												<td>
												<c:forEach var="range" items="${ranges['110']}">
														<c:if test='${customer.industryId == range.id}'>${range.rangeValue}</c:if>
													</c:forEach>
												</td>
												<td>
													<c:forEach var="range" items="${ranges['111']}">
														<c:if test='${customer.areaId == range.id}'>${range.rangeValue}</c:if>
													</c:forEach>
												</td>
												<td>${customer.linkmanNum}</td>
												<td>${customer.linkNum}</td>
												<td>
													${customer.saleStage}
													<font color="red">
													<c:choose>
														<c:when test="${customer.saleStatus == '1'}">[挂起]</c:when>
														<c:when test="${customer.saleStatus == '4'}">[关闭商机]</c:when>
													</c:choose>
													</font>
												</td>
												<td>
													<c:choose>
														<c:when test="${not empty customer.predictCost}">
															￥&nbsp;<fmt:formatNumber value="${customer.predictCost}" pattern="###,###,###,###"/>
														</c:when>
														<c:otherwise>￥&nbsp;0.00</c:otherwise>
													</c:choose>
													
												</td>
												<td><fmt:formatDate value="${customer.predictContract}" pattern="yyyy-MM-dd"/></td>
											</tr>
											</c:forEach>
											</c:when>
											<c:otherwise><tr><td colspan="9" align="center"><img src="./images/nodata.bmp"></td></tr></c:otherwise>
											</c:choose>
										</table>
										</div>
									</td>
								</tr>
								<tr>
									<td align="left" valign="bottom">
										<!-- page -->
										<table id="tp" class="table_page">
											<tr>
												<td>&nbsp;&nbsp;
													<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
													<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
													<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
													共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<input id="customerCode" name="customerCode" type="hidden" value="${queryCustomer.customerCode}"/>
	<input id="customerName" name="customerName" type="hidden" value="${queryCustomer.customerName}"/>
	<input id="industryId" name="industryId" type="hidden" value="${queryCustomer.industryId}"/>
	<input id="areaId" name="areaId" type="hidden" value="${queryCustomer.areaId}"/>
	<input id="salePersonId" name="salePersonId" type="hidden" value="${queryCustomer.salePersonId}"/>
	<input id="customerSourceId" name="customerSourceId" type="hidden" value="${queryCustomer.customerSourceId}"/>
	<input id="requireDesc" name="requireDesc" type="hidden" value="${queryCustomer.requireDesc}"/>
	<input id="startCreateDate" name="startCreateDate" type="hidden" value="${queryCustomer.startCreateDate}"/>
	<input id="endCreateDate" name="endCreateDate" type="hidden" value="${queryCustomer.endCreateDate}"/>
	<input id="startLastLinkDate" name="startLastLinkDate" type="hidden" value="${queryCustomer.startLastLinkDate}"/>
	<input id="endLastLinkDate" name="endLastLinkDate" type="hidden" value="${queryCustomer.endLastLinkDate}"/>
	<input id="sFlag" name="sFlag" type="hidden" value="${sFlag}"/>
	
	<input id="sortSign" name="sortSign" type="hidden" value="${sortSign}"/>
	<input id="sortRecord" name="sortRecord" type="hidden" value="${queryCustomer.sortRecord}"/>
	<input id="sortWay" name="sortWay" type="hidden" value="${queryCustomer.sortWay}"/>
	<input id="imgId" name="imgId" type="hidden" value="${imgId}"/>
</form>
</body>
</html>